package cn.sumpu.app.guoguojie.biz.impl;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import cn.sumpu.app.guoguojie.biz.AppActivityBiz;
import cn.sumpu.app.guoguojie.dao.AppActivityDao;
import cn.sumpu.app.guoguojie.domain.AppActivity;
import cn.sumpu.app.guoguojie.domain.Ext.AppActivityExt;
import cn.sumpu.app.guoguojie.exception.AppBusinessException;
import cn.sumpu.app.guoguojie.util.Common;

public class AppActivityBizImpl implements AppActivityBiz {
	private AppActivityDao appActivityDao;

	public void setAppActivityDao(AppActivityDao appActivityDao) {
		this.appActivityDao = appActivityDao;
	}

	@Override
	public void insert(AppActivity appActivity) throws AppBusinessException {
		appActivityDao.insert(appActivity);
	}

	@Override
	public void update(AppActivity appActivity) throws AppBusinessException {
		appActivityDao.update(appActivity);

	}

	@Override
	public AppActivityExt getAppActivityById(String identifier)
			throws AppBusinessException {
		return appActivityDao.getAppActivityById(identifier);
	}

	@Override
	public void deleteById(String identifier) throws AppBusinessException {
		appActivityDao.deleteById(identifier);

	}

	@Override
	public List<List<AppActivityExt>> getAppActivity(Map<String, Object> map)
			throws AppBusinessException {
		List<List<AppActivityExt>> aList = new ArrayList<List<AppActivityExt>>();
		DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");

		for (int i = 0; i < 7; i++) {
			String beginToday = format1.format(new Date()) + " 00:00:00";
			beginToday = Common.addDate(beginToday, i);
			String endToday = format1.format(new Date()) + " 23:59:59";
			endToday = Common.addDate(endToday, i);
			map.put("beginToday", beginToday);
			map.put("endToday", endToday);
			map.put("startId", 0);
			map.put("pageSize", 4);
			List<AppActivityExt> list = appActivityDao.getAppActivity(map);
			aList.add(list);
		}

		return aList;

	}

	@Override
	public List<AppActivityExt> getAllAppActivity(Map<String, Object> map)
			throws AppBusinessException {
		String beginToday = map.get("postDate").toString() + " 00:00:00";
		String endToday = map.get("postDate").toString() + " 23:59:59";
		int pageSize = 3;
		int pageIndex = (Integer) map.get("pageIndex");
		map.put("beginToday", beginToday);
		map.put("endToday", endToday);
		map.put("startId", (pageIndex - 1) * pageSize);
		map.put("pageSize", pageSize);
		List<AppActivityExt> list = appActivityDao.getAppActivity(map);
		return list;
	}

	@Override
	public int getAppActivityCount(Map<String, Object> map)
			throws AppBusinessException {
		String beginToday = map.get("postDate").toString() + " 00:00:00";
		String endToday = map.get("postDate").toString() + " 23:59:59";
		map.put("beginToday", beginToday);
		map.put("endToday", endToday);
		return appActivityDao.getAppActivityCount(map);
	}

	@Override
	public List<AppActivityExt> getMyFamilyAppActivity(Map<String, Object> map)
			throws AppBusinessException {
		int pageSize = 3;
		int pageIndex = (Integer) map.get("pageIndex");
		map.put("startId", (pageIndex - 1) * pageSize);
		map.put("pageSize", pageSize);
		List<AppActivityExt> list = appActivityDao.getMyFamilyAppActivity(map);
		return list;
	}

	@Override
	public int getMyFamilyAppActivityCount(Map<String, Object> map)
			throws AppBusinessException {

		return appActivityDao.getMyFamilyAppActivityCount(map);
	}

	@Override
	public List<AppActivityExt> getMyFamilyJoinAppActivity(
			Map<String, Object> map) throws AppBusinessException {
		int pageSize = 3;
		int pageIndex = (Integer) map.get("pageIndex");
		map.put("startId", (pageIndex - 1) * pageSize);
		map.put("pageSize", pageSize);
		List<AppActivityExt> list = appActivityDao
				.getMyFamilyJoinAppActivity(map);
		return list;
	}

	@Override
	public int getMyFamilyJoinAppActivityCount(Map<String, Object> map)
			throws AppBusinessException {
		return appActivityDao.getMyFamilyJoinAppActivityCount(map);
	}

	@Override
	public List<AppActivityExt> getRegisteredList(Map<String, Object> map)
			throws AppBusinessException {
		List<AppActivityExt> list=appActivityDao.getRegisteredList(map);
		return list;
	}

	@Override
	public int getRegisteredListCount(String activityId)
			throws AppBusinessException {
		return appActivityDao.getRegisteredListCount(activityId);
	}

}
